﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

namespace GrafikaImbaSekali
{
    public partial class Form1 : Form
    {        
        // border untuk view port
        private int vpUp;
        private int vpLeft;

        //untuk drawing
        private Pen pen;
        private int radius;
        private int move;
        private int zoom;
        
        //untuk sementara belum yang dari excel
        private Point[] AP;
        private Point[] APDraw;

        // graphics
        Graphics g;
        public Form1()
        {            
            vpUp = 0;
            vpLeft = 0;

            pen = new Pen(Color.Black);
            radius = 30;// radius lingkaran
            move = 50;//buat pindah 
            zoom = 1;

            AP = new Point[10];
            initiate();//inisiasi point belum pake excel

            APDraw = new Point[10];
            initDraw();//inisiasi yang di viex port ga tau bener ato salah
            
            InitializeComponent();

            //g = panel1.CreateGraphics();            
            //g.DrawEllipse(pen, 400, 400, 30, 30);
            //g.Dispose();
            //drawAll();// gambar semua
        }

        public void initiate()
        {
            AP[0].X = 151;
            AP[0].Y = 126;
            AP[1].X = 378;
            AP[1].Y = 131;
            AP[2].X = 313;
            AP[2].Y = 305;
            AP[3].X = 586;
            AP[3].Y = 453;
            AP[4].X = 688;
            AP[4].Y = 578;
            AP[5].X = 644;
            AP[5].Y = 311;
        }

        public void initDraw()
        {
            for (int i = 0; i < 6; i++)
            {
                APDraw[i].X = AP[i].X - vpLeft;
                APDraw[i].Y = AP[i].Y - vpUp;
            }
        }

        public void drawAll()
        {
            Graphics ga = panel1.CreateGraphics();
            ga.Clear(panel1.BackColor);
            for (int i = 0; i < 6; i++)
            {
                if (APDraw[i].X > 0 || APDraw[i].Y > 0)//kalo ada pada viewport
                {
                    ga.DrawEllipse(pen, APDraw[i].X, APDraw[i].Y, 30, 30);
                }
            }
            ga.Dispose();
        }

        private void button7_Click(object sender, EventArgs e)
        {
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            drawAll();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (vpUp < 1050)
            {
                vpUp += move;
                initDraw();
                drawAll();
            }            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (vpLeft < 650)
            {
                vpLeft += move;
                initDraw();
                drawAll();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (vpUp > 0)
            {
                vpUp -= move;
                initDraw();
                drawAll();
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            if (vpLeft > 0)
            {
                vpLeft -= move;
                initDraw();
                drawAll();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }
    }
}
